<%@ page import="com.wuchao.service.serviceimpl.ProductImpl" %>
<%@ page import="com.wuchao.entity.Product" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 吴超
  Date: 2022/4/15
  Time: 15:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
        request.setCharacterEncoding("utf-8");
        String op=request.getParameter("op");
        if(op!=null){
            ProductImpl pl=new ProductImpl();
            if(op.equals("delete")){
                    Integer id=Integer.parseInt(request.getParameter("id"));
                  int num=  pl.update("delete from product where id=?",id);
                  if(num>0){
                      request.getRequestDispatcher("main.jsp?isdelete1=true").forward(request,response);
                  }else{
                      response.sendRedirect("main.jsp?isdelete2=false");
                  }
            }if(op.equals("add")){
                String name=request.getParameter("name");
                int flage=Integer.parseInt(request.getParameter("radio")) ;
                 String sex=   request.getParameter("select");

                int num=  pl.update("insert product(name,sex,flage)values(?,?,?)",name,sex,flage);
                if(num>0){
                    request.getRequestDispatcher("main.jsp?isadd1=true").forward(request,response);
                }else{
                    response.sendRedirect("main.jsp?isadd2=false");
                }
            }if(op.equals("update1")){
                int id=Integer.parseInt(request.getParameter("id")) ;
                /*String name=request.getParameter("name");
                String sex=   request.getParameter("sex");
                int flage=Integer.parseInt(request.getParameter("flage")) ;*/
                request.getRequestDispatcher("update.jsp?id="+id).forward(request,response);
            }if(op.equals("update2")){
                Integer id=Integer.parseInt(request.getParameter("id"));
                String name=request.getParameter("name");
                int flage=Integer.parseInt(request.getParameter("radio")) ;
                String sex=   request.getParameter("select");
                int num=  pl.update("update product set name=?,sex=?,flage=? where id=?",name,sex,flage,id);
                if(num>0){
                    request.getRequestDispatcher("main.jsp?isupdate1=true").forward(request,response);
                }else{
                    response.sendRedirect("main.jsp?isupdate2=false");
                }
            }
            else{
                response.sendRedirect("main.jsp");
            }
        }else{
            response.sendRedirect("main.jsp");
        }

%>
</body>
</html>
